﻿using System;
using System.IO;
using MSPP = Microsoft.Office.Interop.PowerPoint;

namespace PowerPointToPdf
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var fileInfo = new FileInfo("Temp/Test.pptx");
            Console.WriteLine(fileInfo.FullName);
            MSPP.ApplicationClass application = null;
            MSPP.Presentation persentation = null;

            try
            {
                application = new MSPP.ApplicationClass();
                persentation = application.Presentations.Open(fileInfo.FullName);
                persentation.SaveAs( new FileInfo($"Temp/{Path.GetFileNameWithoutExtension(fileInfo.FullName)}.pdf").FullName, MSPP.PpSaveAsFileType.ppSaveAsPDF);
            }catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                persentation?.Close();
                application?.Quit();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
    }
}
